<!--
 * @Author: ssj
 * @Date: 2021-06-26 17:51:15
 * @LastEditors: wiz
 * @LastEditTime: 2023-12-22 16:33:59
 * @Description: color组件
-->
<template>
  <div class="o-color-cell">
    <span
      :class="{ 'read-only': renderOpts.props.disabled }"
      :style="{ backgroundColor: value }"
    ></span>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
import { Tsrv } from '@/services';

@Component
export default class oColorCell extends Vue {
  @Prop() params: any;

  private value = null;

  private format = null;

  @Watch('params')
  onParamsChange() {
    this.setValue();
  }

  @Prop() renderOpts: any;

  @Watch('renderOpts')
  onRenderOptsChange() {
    this.init();
  }

  mounted() {
    this.init();
    this.setValue();
  }

  init() {
    this.format = this.renderOpts.props['format'];
  }

  setValue() {
    if (this.params.property) {
      this.value = this.params.data[this.params.property];
    } else if (this.params.column) {
      this.value = this.params.row[this.params.column.property];
    }
  }
}
</script>

<style scoped lang="scss">
.o-color-cell {
  > span {
    display: block;
    width: 20px;
    height: 20px;
  }
}
</style>
